// Create the directory application.
angular.module('directoryModule', ['directoryDirectives', 'directoryServices', 'directoryFilters'])
	
// Register work which needs to be performed on module loading.
.config([
	'$routeProvider', '$locationProvider',
	function($routeProvider, $locationProvider) {
		// Setup deep linking.
		$routeProvider
			.when('/', { controller: 'StatefulController', templateUrl: 'resources/templates/home.html' })
			.when('/home', { controller: 'DirectoryController', templateUrl: 'resources/templates/home.html' })
			.when('/welcome', { controller: 'DirectoryController', templateUrl: 'resources/templates/home.html' })

			// Otherwise redirect the user to home.
			.otherwise({ redirectTo: '/home' });

		// Setup location services.
		$locationProvider.html5Mode(true).hashPrefix('!');
	}
])

// The directory controller.
.controller('DirectoryController', function($scope, $http, $rootElement) {
	// Get the directories and save them into the scope.
	$http({ method: 'GET', url: 'resources/json/home.json', cache: true }).success(function(data) {
		$scope.directories = data;
	});
});